package top.mybatisx.plugin_proxy.service;


import top.mybatisx.plugin_proxy.plugin.ClockInPlugin;
import top.mybatisx.plugin_proxy.plugin.ClockType;
import top.mybatisx.plugin_proxy.plugin.impl.ClockInPluginImpl;
import top.mybatisx.plugin_proxy.plugin.impl.DingDingClockInPluginImpl;
import top.mybatisx.plugin_proxy.plugin.impl.WeixinClockInPluginImpl;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 考勤业务
 */
public class ClockInService implements InvocationHandler {

    private ClockType clockType;

    /**
     * 考勤执行
     */
    public ClockInService(ClockType clockType) {
        this.clockType = clockType;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("-----------可定义拦截器---------");
        if (args != null) {
            for (Object arg : args) {
                System.out.println("通过代理拿到了参数：" + arg);
            }
        }
        // 初始化插件
        ClockInPlugin clockInPlugin = switch (clockType) {
            case sytem -> new ClockInPluginImpl();
            case dingding -> new DingDingClockInPluginImpl();
            case weixin -> new WeixinClockInPluginImpl();
        };
        return method.invoke(clockInPlugin, args);
    }

}
